package map;

import java.util.Arrays;

import org.apache.commons.lang3.ArrayUtils;

import data.Data;

public class MapData extends Data {

	//Std Constructor
	private MapData(byte req) {
		this.data = new byte[1];
		this.data[0] = req;
	}

	public MapData(byte[] data) {
		super(data);
	}

	@Override
	public byte[] getDataWithHeader() {
		short len = (short)(data.length+3);
		byte[] header = new byte[3];
		
		header[0] = (byte)len;
		header[1] = (byte)(len >> 8);
		header[2] = Data.MAP_DATA;
		//Concatenate Arrays
		byte[] bytes = ArrayUtils.addAll(header,this.data);
		return bytes;
	}
	
	@Override
	public String toString() {
		return data.toString();
	}
	
	public static synchronized MapData request(int number) {
		return new MapData((byte)number);
	}
	
	@Override
	public void process(short len) {
		//System.out.println(Arrays.toString(data));
		System.out.println("MapData " + data[0] + " : " + len);
		MapChunk one = MapChunk.load(data);
		one.draw();
	}
	
	

	
	
}
